package com.zpc.browser;

import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author : zpc20 //作者
 * @version : 1.0 // 版本
 * @ClassName : ServerResponse  //类名
 * @Description : 服务端返回数据  //描述
 * @Date: 2024-12-03  下午 10:03
 */
public class ServerResponse {
    public static void main(String[] args) {
        try(
                ServerSocket server = new ServerSocket(8080)
        ){
            System.out.println("My Server started");
            Socket socket = server.accept();
            System.out.println("Client connected "+socket.getInetAddress().getHostAddress());
            OutputStreamWriter os = new OutputStreamWriter(socket.getOutputStream());
            os.write("HTTP/1.1 200 OK\r\n");
            os.write("Content-Type: text/html;charset=utf-8\r\n");
            os.write("\r\n");
            // 返回体
            os.write("测试你好~~~~~~~~~");
            os.flush();
        }catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
